package com.xywy.bloodandroid.adapter;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.xywy.bloodandroid.R;
import com.xywy.bloodandroid.act.ArticleDetailActivity;
import com.xywy.bloodandroid.bean.CollectData;

/**
 * 我的收藏列表适配器
 */
public class CollectAdapter extends BaseAdapter {

	private Context context;
	private List<CollectData> datas = new ArrayList<CollectData>();

	public CollectAdapter(Context context, List<CollectData> data) {
		this.context = context;
		this.datas = data;
	}

	@Override
	public int getCount() {
		return datas.size();
	}

	@Override
	public Object getItem(int arg0) {
		return datas.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		return arg0;
	}

	@Override
	public View getView(final int position, View view, ViewGroup arg2) {
		ViewHolder holder;
		if (view == null) {
			holder = new ViewHolder();
			view = View.inflate(context, R.layout.item_collect_list, null);
			holder.tv_title = (TextView) view.findViewById(R.id.tv_title);
			holder.ll_click = (LinearLayout) view.findViewById(R.id.ll_click);
			view.setTag(holder);
		} else {
			holder = (ViewHolder) view.getTag();
		}
		holder.tv_title.setText(datas.get(position).getTitle());
		holder.ll_click.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// Toast.makeText(context,
				// "打开CollectAdapter下，此toast下的注释内容，并且在接收类中做好处理",
				// Toast.LENGTH_SHORT).show();

				String[] content = datas.get(position).getMeta().split(",");
				Intent intent = new Intent(context, ArticleDetailActivity.class);
				intent.putExtra("dirStr", content[0]);
				intent.putExtra("typeid", content[1]);
				intent.putExtra("id", datas.get(position).getCategoryid());
				context.startActivity(intent);

			}
		});
		return view;
	}

	class ViewHolder {
		TextView tv_title;
		LinearLayout ll_click;
	}
}
